﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PromoServer.Library.Data;
using PromoServer.Library.Entities;
using System.Collections.ObjectModel;

namespace PromoServer.Library.BLL
{
    public class PSSchedule
    {
        #region Properties

        private PSData _psData;

        public ObservableCollection<string> ValidPeriods
        {
            get
            {
                List<string> validPeriods = new List<string>();
                validPeriods.Add("AM");
                validPeriods.Add("PM");
                return new ObservableCollection<string>(validPeriods);
            }
        }

        #endregion

        public PSSchedule()
        {
            _psData = new PSData();
        }

        public List<Schedule> GetSchedules()
        {
            try
            {
                List<Schedule> lstSchedules;
                lstSchedules = _psData.GetSchedules();
                return lstSchedules;
            }
            catch (Exception ex)
            {
                // Log error
                PromoLog promoLog = new PromoLog();
                promoLog.Log("PSSchedule.GetSchedules", ex.Message, true);
                return null;
            }
        }

        public int AddSchedule(Schedule newSchedule)
        {
            try
            {
                return _psData.AddSchedule(newSchedule);
            }
            catch (Exception ex)
            {
                // Log error
                PromoLog promoLog = new PromoLog();
                promoLog.Log("PSSchedule.AddSchedule", ex.Message, true);
                return -1;
            }
        }

        public bool UpdateSchedule(Schedule updatedSchedule)
        {
            try
            {
                _psData.UpdateSchedule(updatedSchedule);
                return true;
            }
            catch (Exception ex)
            {
                // Log error
                PromoLog promoLog = new PromoLog();
                promoLog.Log("PSSchedule.AddSchedule", ex.Message, true);
                return false;
            }
        }

        public bool DeleteSchedule(Schedule deletedSchedule)
        {
            try
            {
                _psData.DeleteSchedule(deletedSchedule);
                return true;
            }
            catch (Exception ex)
            {
                // Log error
                PromoLog promoLog = new PromoLog();
                promoLog.Log("PSSchedule.DeleteSchedule", ex.Message, true);
                return false;
            }
        }
    }
}
